<%--
  Created by IntelliJ IDEA.
  User: 22328
  Date: 2021/2/7
  Time: 22:51
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>用户添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <%--<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->--%>
    <%--<!--[if lt IE 9]>--%>
    <%--<script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>--%>
    <%--<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>--%>
    <%--<![endif]-->--%>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <div class="layui-form" onsubmit="return false">
            <div class="layui-form-item">
                <label for="username" class="layui-form-label">
                    <span class="x-red">*</span>商户名
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="username" name="username" value=""
                           class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>将会成为您唯一的登入名
                </div>
            </div>
            <div class="layui-form-item">
                <label for="age" class="layui-form-label">
                    <span class="x-red">*</span>年限
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="age" name="age" value="" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="phone" class="layui-form-label">
                    <span class="x-red">*</span>手机
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="phone" name="phone" value=""
                           class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>将会成为您唯一的登入名
                </div>
            </div>
            <div class="layui-form-item">
                <label for="L_email" class="layui-form-label">
                    <span class="x-red">*</span>邮箱
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="L_email" name="email" value=""
                           class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>注意正确的邮箱格式
                </div>
            </div>
            <div class="layui-form-item">
                <label for="L_pass" class="layui-form-label">
                    <span class="x-red">*</span>密码
                </label>
                <div class="layui-input-inline">
                    <input type="password" id="L_pass" name="pass" value=""
                           class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>6到16个字符
                </div>
            </div>
            <div class="layui-form-item">
                <label for="L_repass" class="layui-form-label">
                    <span class="x-red">*</span>确认密码
                </label>
                <div class="layui-input-inline">
                    <input type="password" id="L_repass" name="repass" value=""
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">用户角色</label>
                <div class="layui-input-inline">
                    <select id="role_id" name="role_id">
                        <option value="3">商家</option>
                        <option value="2">普通用户</option>
                        <option value="1">管理员</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                </label>
                <button id="add_btn" class="layui-btn">
                    添加
                </button>
            </div>
        </div>
    </div>
</div>
</body>
<script src="./js/jquery-3.1.0.min.js" type="text/javascript"></script>
<script>
    layui.use(['form', 'layer'], function () {
        var form = layui.form,
            layer = layui.layer;
    });
    $(function () {
        $("#add_btn").click(function () {
            var username = $("#username").val();
            var age = $("#age").val();
            var phone = $("#phone").val();
            var email = $("#L_email").val();
            var password = $("#L_pass").val();
            var roleId = $("#role_id").val();
            $.ajax({
                url: "./addUser",
                type: "post",
                data: {
                    username: username,
                    age: age,
                    phone: phone,
                    email: email,
                    password: password,
                    roleId:roleId
                },
                success: function (res) {
                    if (res.data === "添加成功") {
                        layer.alert("添加成功", {
                                icon: 6
                            },
                            function () {
                                //关闭当前frame
                                xadmin.close();
                                // 可以对父窗口进行刷新
                                xadmin.father_reload();
                            });
                    } else {
                        layer.msg("修改失败");
                    }
                },
                error: function () {
                    alert("404.html页面");
                }
            });
        });
    });
</script>
</html>

